/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package horizon.gui.component;

import horizon.graphics.RenderingContext;
import horizon.util.Vector2;
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.geom.Rectangle2D;

/**
 *
 * @author J_Laptop
 */
public class GuiLoadingBar extends GuiComponent {

    Color bgColor;
    Color outlineColor;
    Color highlightColor;
    Rectangle2D highlightBox;
    float max = 0;
    float cur = 0;

    public GuiLoadingBar( String name, Vector2 position, Vector2 size , Color bgColor, Color outlineColor, Color highlightColor) {
        super(name, size, position);
        
        this.bgColor = bgColor;
        this.outlineColor = outlineColor;
        this.highlightColor = highlightColor;
        
        highlightBox = new Rectangle(position.getPoint() , new Vector2(0).getDim());
        
        
    }

    

    @Override
    public void update(long elapsedTime) {
        
    
            
    
        
    }
    
    public void setMax(int m){
        
        max = m;
        
    }
    
    public void setCur(int c){
        
        if(c <= max)
            cur = c;
        else
            cur = max;
        
    }

    @Override
    public void render(RenderingContext r) {
        
        float width = (cur / max) * size.getX();
        highlightBox = new Rectangle(position.getPoint() , new Vector2(width , size.getY()).getDim());
        
        r.drawFilledRectangle(componentBox, bgColor);
        r.drawRectangle(componentBox, outlineColor);
        r.drawFilledRectangle(highlightBox, highlightColor);
        
        String text = ((int)((cur / max) * 100)) + "%";
        
        int strWidth = r.getGraphics().getFontMetrics().stringWidth(text);
        r.drawText(text, position.add(size.div(2)).sub(new Vector2(strWidth / 2, 0)), Color.ORANGE);
        
    }

    @Override
    public void onActivate(MouseEvent e) {
     
    }

    
}
